package com.itheima;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {
        test2();
        test1();
    }
    private static void test2() {
        TreeMap<Student,String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()-o1.getAge();
            }
        });
        treeMap.put(new Student("张三",23),"广州");
        treeMap.put(new Student("李四",16),"深圳");
        treeMap.put(new Student("王五",20),"北京");
        treeMap.put(new Student("赵六",21),"上海");
        treeMap.put(new Student("田七",18),"杭州");
        treeMap.forEach((k,v)-> System.out.println(k+"-->"+v));
    }
        HashMap<Student,String> map = new HashMap<>();

    private static void test1() {
        TreeMap<Student,String> treeMap = new TreeMap<>();
        treeMap.put(new Student("张三",18),"广州");
        treeMap.put(new Student("李四",24),"深圳");
        treeMap.put(new Student("王五",20),"北京");
        treeMap.put(new Student("赵六",26),"上海");
        treeMap.put(new Student("田七",17),"杭州");
        System.out.println("--------------------------------");
        treeMap.forEach((k,v)-> System.out.println(k+"-->"+v));
    }

}
